# -*- coding:utf-8 -*-
# @Author: shenyuyu
# @Time: 2023/6/26 10:59
# @File: qu_4_fold.py
from pyspark import SparkConf, SparkContext
from operator import add

if __name__ == '__main__':
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    sc = SparkContext(conf=conf)

    rdd = sc.parallelize([1, 2, 3, 4, 5, 6], 2)

    print(rdd.getNumPartitions())

    # 分区内用初始值做聚合，分区之间也加上初始值，哪怕只有一个分区
    result = rdd.fold(10, add)
    print(result)